﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Croxweb.Leuphana.Models;
using System.Collections.Generic;

namespace Croxweb.Leuphana.Services.MyStudyService
{
    public interface IMyStudyService
    {
        void SetCredentials(MyStudyCredentials credentials);

        Lecture GetLecture(int id);

        Message GetMessage(int id);
        IEnumerable<Message> GetLatestMessages(int limit);
        IEnumerable<Message> GetLectureMessages(int lectureId);

        Appointment GetAppointment(int id);
        IEnumerable<Appointment> GetLectureAppointments(int lectureId);
        IEnumerable<Appointment> GetAllAppointments();
        NextEventList GetNextAppointments(int limit);

        void Authorize(String password, Action<MyStudyResult, String> callback);

        void GetPerson(int id, Action<MyStudyResult, PersonDetail> callback);
        void SearchPersons(String name, Action<MyStudyResult, IEnumerable<Person>> callback);

        void SynchronizeMessages(Action<MyStudyResult> callback);
        void SynchronizeSchedule(Action<MyStudyResult> callback);
    }

    public class NextEventList : List<Appointment>
    {
        private DateTime startDate;

        public NextEventList(DateTime startDate, IEnumerable<Appointment> appointments) {
            this.AddRange(appointments);
            this.startDate = startDate;
        }

        public DateTime StartDate
        {
            get { return startDate; }
        }
    }

    public class MyStudyCredentials
    {
        private readonly String username;
        private readonly String password;
        private readonly String semester;

        public MyStudyCredentials(String username, String password, String semester)
        {
            this.username = username;
            this.password = password;
            this.semester = semester;
        }

        public String Username
        {
            get { return username; }
        }

        public String Password
        {
            get { return password; }
        }

        public String Semester
        {
            get { return semester; }
        }
    }

    public enum MyStudyResult
    {
        Success,
        AccessDenied,
        UnreachableServer,
        UnknownError
    }
}
